//
//  STLChannelCollectionViewCell.m
//  STL_ Animation
//
//  Created by 孙健 on 16/3/31.
//  Copyright © 2016年 STL. All rights reserved.
//

#import "STLChannelCollectionViewCell.h"

@implementation STLChannelCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        self.imageViewChannel = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.imageViewNew = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.labelChannel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.labelType = [[UILabel alloc] initWithFrame:CGRectZero];
        
        self.labelType.textAlignment = NSTextAlignmentCenter;
        self.labelChannel.textColor = [UIColor whiteColor];
        self.labelChannel.font = [UIFont systemFontOfSize:14];
        
        self.colorView = [[UIView alloc] init];
        [self.contentView addSubview:self.colorView];
        [self.colorView addSubview:self.imageViewChannel];
        [self.colorView addSubview:self.imageViewNew];
        
        self.layerName = [CAGradientLayer layer];
        
        self.layerName.startPoint = CGPointMake(0, 0);
        self.layerName.endPoint = CGPointMake(0, 1);
        self.layerName.colors = @[(__bridge id)[UIColor clearColor].CGColor,(__bridge id)[UIColor blackColor].CGColor];
        self.layerName.locations = @[@(0.5f),@(1.0f)];
      
        [self.contentView.layer addSublayer:self.layerName];
        [self.contentView addSubview:self.labelChannel];
        [self.contentView addSubview:self.labelType];
    }
    
    return self;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
   
    
    self.imageViewChannel.frame = self.contentView.bounds;
    self.imageViewNew.frame = CGRectMake(0, 0, self.contentView.bounds.size.width/6, self.contentView.bounds.size.width/6);
    self.labelChannel.frame = CGRectMake(10, self.contentView.bounds.size.height - 30, self.contentView.bounds.size.width, 30);
    self.labelType.frame = CGRectMake(self.contentView.bounds.size.width - 30, 0, 30, 20);
    self.layerName.frame = self.imageViewChannel.bounds;
    
}

- (void)setChannelModel:(ChannelBaseModel *)channelModel {
    
    _channelModel = channelModel;
    [self.imageViewChannel sd_setImageWithURL:[NSURL URLWithString:channelModel.img]placeholderImage:[UIImage imageNamed:@"logoimage"]];
    
    if ([channelModel.flag isEqualToString:@"new"]) {
        
        self.imageViewNew.image = [UIImage imageNamed:@"new"];
        
    }else {
        
        
        
        self.imageViewNew.image = [UIImage imageNamed:@"kongbai"];
                
    }
    
    if ([channelModel.type isEqualToString:@"program"]) {
        self.labelType.backgroundColor = [UIColor colorWithRed:8/255.0 green:146/25.0 blue:114/255.0 alpha:1];
        self.labelType.textColor = [UIColor whiteColor];
        self.labelType.font = [UIFont systemFontOfSize:11];
        self.labelType.text = @"节目";
    }else {
        
        self.labelType.backgroundColor = [UIColor clearColor];
        self.labelType.text = @"";
    }
    
    self.labelChannel.text = channelModel.title;
}





@end
